package server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import db.DBmanager;

/**
 * Servlet implementation class ColorServlet
 */
public class ColorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ColorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName="";
		try{
		userName=request.getParameterValues("userName")[0];
		}catch(Exception e){
			PrintWriter out=response.getWriter();
			out.write("bad arguments for userName");
			response.setStatus(400);
		}
		try{
			String streets=DBmanager.getDB().colorMap(userName);
			PrintWriter out=response.getWriter();
			out.write(streets);
			response.setStatus(200);
			return;
		}catch(Exception e){
			e.printStackTrace();
			response.sendError(400,"we have encountred a technical problem, please login again");
			return;
		}	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
